package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 统计：1按年度，2按门类
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum StatisticsTypeEnum {
  YEAR(1, "年度", "year"),
  ARCH_TYPE(2, "门类", "archTypeName"),
  DEPT_ID(3, "部门", "deptId"),
  USING_USER(4, "利用人", "username"),
  RETENTION_PERIOD(5, "保管期限", "retentionPeriod"),
  FILLING_PERSON(6, "办理人", "fillingPerson"),
  WORK_TYPE(7, "利用方式", "workType"),
  ;

  private Integer code;
  private String desc;
  private String groupField;

  public static StatisticsTypeEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到档案状态：" + type));
  }

  @JsonCreator
  public static StatisticsTypeEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
